#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    FILE *fp;
    char a[3][10],temp[10];
    int i,j,k,n=3;
    printf("Enter string:\n");
    for(i=0;i<n;i++){
        scanf("%s",a[i]);
    }
    for(i=0;i<n-1;i++){
        k=i;
        for(j=i+1;j<n;j++){
            if(strcmp(a[k],a[j])>0) k=j;
        }
        if(k!=i){
            strcpy(temp,a[i]);
            strcpy(a[i],a[k]);
            strcpy(a[k],temp);
        }
        while((fp=fopen("D:\\string.dat","w"))==NULL){
            printf("cannot open file");
            exit(0);
        }
        printf("now string:\n");
        for(i=0;i<n;i++){
            fputs(a[i],fp);
            fputs("\n",fp);
            printf("%s\n",a[i]);
        }
    }
    fclose(fp);
    return 0;
}
